home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT22.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.7 KB  |  113 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 22                         
  5.                                           
  6.  This is a small program 'template' to help you get started with the sprite  
  7.  library.                                                                    
  8.                                           
  9.  *** PROJECT ***                                                             
  10.  This program requires the files WSPR_WC.LIB and WGT5_WC.LIB to be linked.   
  11.                                           
  12.  *** DATA FILES ***                                                          
  13.  Make sure that INVADER.SPR is in your executable directory.                 
  14.                                WATCOM C++ VERSION 
  15. ==============================================================================
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <dos.h>
  20. #include <conio.h>
  21. #include <stdlib.h>
  22. #include <malloc.h>
  23. #include <wgt5.h>
  24. #include <wgtspr.h>
  25.  
  26. color palette[256];             
  27. block sprites[20];
  28. int quit;                               /* if quit !=0, program quits */
  29. int oldmode;
  30.  
  31. void looper (void);                      /* a routine which controls the sprites */
  32.  
  33. void main (void)
  34. {
  35.   if ( !vgadetected () )
  36.   {
  37.     printf("Error - VGA card required for any WGT program.\n");
  38.     exit (0);
  39.   }
  40.   printf ("WGT Example #22\n\n");
  41.   printf ("Sprite movement and animation is demonstrated in this short demo.\n");
  42.   printf ("Press any key to end the program. Try inserting a delay to slow down the\n");
  43.   printf ("animation.\n");
  44.   printf ("\n\nPress any key to continue.\n");
  45.   getch ();
  46.  
  47.   oldmode = wgetmode();
  48.   vga256 ();
  49.   wloadsprites (palette, "invader.spr", sprites, 0, 19);
  50.   /* load first 50 sprites */
  51.   wsetpalette (0, 255, palette);
  52.  
  53.   initialize_sprites (sprites);                  /* initialize them */
  54.   maxsprite = 2;                                 /* number of sprites on */
  55.  
  56. /* Spriteon has the following format:
  57.    Sprite number, x coord, y coord, sprite number in array of sprites
  58.    Therefore sprite #1 would be displayed at 160,100 with sprite 1 in the array */
  59.  
  60.   spriteon (0, 160, 100, 1);                        /* turn on any sprites */
  61.   spriteon (1, 10, 100, 3);                         /* you need */
  62.  
  63. /* This move will go left 1, for 300 times, and right 1 for 300 times,
  64.    and repeat */
  65.  
  66.   movex (1, "(1,300,0)(-1,300,0)R");              /* set up any movement */
  67.   movexon (1);                                   /* or animation needed */
  68.  
  69.  
  70. /* This animation will animate sprite 2 through a sequence of sprites
  71.    in the sprite array and keep repeating. */
  72.  
  73.   animate (1, "(3,50)(4,50)(5,50)(4,50)R");
  74.   animon (1);
  75.  
  76.   minit ();
  77.  
  78.   do {
  79.     looper ();
  80.   } while (!quit);
  81.   getch ();
  82.  
  83.   mdeinit ();                   /* Deinitialize the mouse handler */
  84.   
  85.   spriteoff (0);                 /* turn off sprites */
  86.   spriteoff (1);
  87.   /* To be safe, turn off all sprites before ending program.
  88.      This will free any memory used from them. */
  89.  
  90.   deinitialize_sprites ();
  91.   wfreesprites (sprites, 0, 19);      /* free memory */
  92.  
  93.   wsetmode (oldmode);
  94. }
  95.  
  96.  
  97. void looper(void)
  98. {
  99.   erase_sprites ();     /* clear the sprites */
  100.  
  101.   s[0].x = mouse.mx;    /* any direct sprite movements must be placed */
  102.   s[0].y = mouse.my;    /* between erasespr and drawspr */
  103.         /* This will set sprite one's coordinate to the mouse
  104.            coordinates. Move it around! */
  105.         /* notice how sprite #2 moves and animates on its own now!
  106.            You don't need to change anything to make it move! */
  107.  
  108.   wretrace ();
  109.   draw_sprites (1);                    /* draw them back on */
  110.   if (kbhit ()) 
  111.     quit = 1;
  112. }
  113.